home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / rexx / 524 < prev    next >
Encoding:
Text File  |  1996-08-06  |  3.8 KB  |  131 lines

  1. Path: explorer.csc.com!not-for-mail
  2. From: mschlege@csc.com (Mark Schlegel)
  3. Newsgroups: comp.lang.rexx
  4. Subject: Re: Bug in OS2's SysFileSearch?
  5. Date: 27 Jan 1996 16:27:18 -0500
  6. Organization: Computer Sciences Corporation
  7. Distribution: world
  8. Message-ID: <4ee5bm$4to@explorer.csc.com>
  9. References: <4dmv4m$899@harbinger.cc.monash.edu.au> <3100e06e.53494d4d4f4e53@simmons.actrix.gen.nz>
  10. NNTP-Posting-Host: explorer.csc.com
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Jim Simmons (jim@simmons.actrix.gen.nz) wrote:
  14. : I heard a rumour that Jobst Schmalenbach <jhs@rdt.monash.edu.au> said:
  15. : >Hi netters,
  16. : >
  17. : > I needed to find the occurences of some string on a complete
  18. : >line in REXX for OS2.
  19. : >
  20. : >Here is what I did (well the most important stuff):
  21. : >
  22. : >....
  23. : >....
  24. : >/* find the files .... */
  25. : >...
  26. : >do i=1 to Files.0
  27. : >  /* i might have mixed up the order of the parameters, i am  at work
  28. : >     not at home, so ... */
  29. : >  rc = SysFileSearch('Path',Files.i,Lines)
  30. : >  if rc\=0 then
  31. : >    CleanUp rc
  32. : >  say 'Found 'Lines.0' lines matching'
  33. : >  do j=1 to Lines.0
  34. : >    /* do some work here, but for the sake just display */
  35. : >    say 'Found: 'Lines.j
  36. : >  end
  37. : >end
  38. : >...
  39. : >...
  40. : >/* do some other stuff */
  41. : >
  42. : >However, for some crazy reason it ALWAYS found ONLY 1 matching line
  43. : >although there were at least 10 entries in EACH file that
  44. : >is Lines.0 showed only ONE entry found.
  45. : >HUH?
  46.  
  47. You have to be careful, I don't see what you do to get
  48. that File. stem but remember that if you are using sysfiletree
  49. to get filenames to put in a stem (looks like Files.i in your prog)
  50. that the stem it returns is a complex set of 5 words of which
  51. the file path is the 5th word:
  52.  
  53. filespec = 'f:\rexx\progs\*.*'
  54. call sysfiletree filespec,'Files','f'
  55.  
  56. would populate stem ->  files. with all the files in path filespec
  57. (note the 'f' option that tells sysfiletree to only get files and not
  58. dirs)
  59.  
  60. but now note your usage of sysfilesearch:
  61.  
  62. rc = sysfilesearch('path',files.i,Lines)
  63.  
  64. note that files.i is wrong UNLESS you do this (and you used sysfiletree):
  65.  
  66. do i = 1 to Files.0
  67.    Files.i = word(Files.i, 5)
  68.    rc = sysfilesearch('path', Files, Lines)
  69.    if rc \= 0 then
  70.       call Cleanup rc
  71.    say 'found' Lines.0 'lines matching'
  72.    do j = 1 to Lines.0
  73.      say "found:" Lines.j
  74.    end
  75. end
  76.  
  77. ==============
  78. or to see a program I just wrote that I know works:
  79. ------- start ---------
  80.  
  81. /*  rexx */
  82.  
  83. filespec = "f:\rexx\progs\cleanup.cmd";  /*  just one file to test*/
  84.                                        /* in real use, likely a
  85.                                      wildcard ie f:\dir1\*.*     */
  86. call sysfiletree filespec,'files','f';
  87. phrase = 'then';              /* <-- key phrase to search for */
  88.  
  89. do i = 1 to files.0
  90.   file = word(files.i, 5);   /* only send filename to sysfilesearch*/
  91.   rc = sysfilesearch(phrase, file, Lines, "n");
  92.   if rc \= 0 then
  93.     call Cleanup rc;    /* whatever that does? */
  94.   say 'found' Lines.0 'lines that match' phrase 'in file' filespec
  95.   do j = 1 to Lines.0
  96.     say "At line #:" Lines.j
  97.   end
  98. end
  99.  
  100. --------- end ------------
  101.  
  102. note that files.i is in general:
  103.  
  104. MM/DD/YY    HH:MM     size(bytes)    attribute_list   filename
  105.  
  106. which is why you must use    word(files.i, 5) to only put word #5
  107. which is the full filename to 'file' .  I then run file in each
  108. iteration of sysfilesearch....or you could just put filename back
  109. to files.i recursively if you want:
  110.  
  111. .......
  112. do i = 1 to files.0
  113.   files.i = word(files.i, 5)
  114.   rc = sysfilesearch(phrase, files.i, Lines,"n")
  115.   if rc \= 0 then
  116.      call Cleanup rc
  117.   say 'Found' Lines.0 'lines that match' phrase
  118.   do j = 1 to Lines.0
  119.     say "Line #:" Lines.j
  120.   end
  121. end
  122.  
  123. =========== end 
  124.  
  125. also note the 'n' option in sysfilesearch, this adds a nice
  126. bit of info to each Lines.j ... it adds the line number of
  127. the match to the start of each Lines.j
  128.  
  129. mark
  130.  
  131.